package com.ruoyi.web.controller.module.property;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.domain.module.property.PropertyRegister;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.module.property.IPropertyRegisterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 物业入驻申请表Controller
 *
 * @author ruoyi
 * @date 2022-10-18
 */
@Validated
@Api(value = "物业入驻申请表控制器", tags = {"物业入驻申请表管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/module/property/register")
public class PropertyRegisterController extends BaseController {

    private final IPropertyRegisterService propertyRegisterService;

    /**
     * 查询物业入驻申请表列表
     */
    @ApiOperation("查询物业入驻申请表列表")
    @PreAuthorize("@ss.hasPermi('module:propertyReg:list')")
    @GetMapping("/list")
    public TableDataInfo<PropertyRegister> list(@Validated PropertyRegister propertyRegister) {
        QueryWrapper<PropertyRegister> qw = new QueryWrapper<>();

        TableDataInfo<PropertyRegister> td = PageUtils.buildDataInfo(propertyRegisterService.page(PageUtils.buildPage(),qw));
        List<PropertyRegister> list = td.getRows();
        return td;
    }

    /**
     * 导出物业入驻申请表列表
     */
    @ApiOperation("导出物业入驻申请表列表")
    @PreAuthorize("@ss.hasPermi('module:propertyReg:export')")
    @Log(title = "物业入驻申请表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<PropertyRegister> export(@Validated PropertyRegister propertyRegister) {
        List<PropertyRegister> list = propertyRegisterService.list();
        ExcelUtil<PropertyRegister> util = new ExcelUtil<PropertyRegister>(PropertyRegister.class);
        return util.exportExcel(list, "物业入驻申请表");
    }

    /**
     * 获取物业入驻申请表详细信息
     */
    @ApiOperation("获取物业入驻申请表详细信息")
    @PreAuthorize("@ss.hasPermi('module:propertyReg:query')")
    @GetMapping("/{id}")
    public AjaxResult<PropertyRegister> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        PropertyRegister propertyRegister = propertyRegisterService.getById(id);
        return AjaxResult.success(propertyRegister);
    }

    /**
     * 新增物业入驻申请表
     */
    @ApiOperation("新增物业入驻申请表")
    @PreAuthorize("@ss.hasPermi('module:propertyReg:add')")
    @Log(title = "物业入驻申请表", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody PropertyRegister propertyRegister) {
        return toAjax(propertyRegisterService.save(propertyRegister) ? 1 : 0);
    }

    /**
     * 修改物业入驻申请表
     */
    @ApiOperation("修改物业入驻申请表")
    @PreAuthorize("@ss.hasPermi('module:propertyReg:edit')")
    @Log(title = "物业入驻申请表", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody PropertyRegister propertyRegister) {
        return toAjax(propertyRegisterService.updateById(propertyRegister) ? 1 : 0);
    }

    /**
     * 删除物业入驻申请表
     */
    @ApiOperation("删除物业入驻申请表")
    @PreAuthorize("@ss.hasPermi('module:propertyReg:remove')")
    @Log(title = "物业入驻申请表" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")  @PathVariable Long[] ids) {
        return toAjax(propertyRegisterService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
